package com.zyt.controller;

import com.zyt.entity.Book;
import com.zyt.entity.Category;
import com.zyt.mapper.CategoryMapper;
import com.zyt.service.BookService;
import com.zyt.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class BookController {
    @Autowired
    private BookService bookService;
    @Autowired
    private CategoryService categoryService;
    @RequestMapping("/selectByRecommend")
    public String selectByRecommend(Model model){
        List<Book> books = bookService.selectByRecommend();
        List<Book> books1 = bookService.selectByHot();
        List<Book> books2 = bookService.selectByNew();
        List<Book> books3 = bookService.selectByright();
        List<Category> categories = categoryService.selectAllCategory();

        model.addAttribute("books",books);
        model.addAttribute("books1",books1);
        model.addAttribute("books2",books2);
        model.addAttribute("books3",books3);
        model.addAttribute("categories",categories);
        return "/main/main.jsp";
    }
    @RequestMapping("/selectByBook")
    public String selectByBook(Integer id,Model model){
        Book book = bookService.selectByBook(id);
        model.addAttribute("book",book);
        return "/main/product.jsp";
    }
    @RequestMapping("/selectByLevelTwo")
    public String selectByLevelTwo(Integer id,Model model){
        List<Book> books = bookService.selectByLevelTwo(id);
        List<Category> categories = categoryService.selectByLevelTwo(id);
        model.addAttribute("books",books);
        model.addAttribute("categories",categories);
        return "/main/book_list.jsp";
    }
    @RequestMapping("/selectByLevelOne")
    public String selectByLevelOne(Integer id,Model model){
        List<Book> books = bookService.selectByLevelOne(id);
        List<Category> categories = categoryService.selectByLevelOne(id);
        model.addAttribute("books",books);
        model.addAttribute("categories",categories);
        return "/main/book_list.jsp";
    }
}
